home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / toolfix.arc / EXTEND.ACC < prev    next >
Text File  |  1987-03-03  |  10KB  |  258 lines

  1. (******************************************************************************
  2.  
  3.                                   EXTEND.ACC
  4.                                   Version 1.1
  5.                                February 27, 1986
  6.                                by Randy Forgaard
  7.                              CompuServe 70307,521
  8.  
  9.  
  10. The following information can be used only with the DOS version of the Turbo
  11. (Database) Toolbox, under Turbo Pascal 3.0 and higher.
  12.  
  13. This file is for use with the Turbo Access portion of the MS-DOS Turbo
  14. (Database) Toolbox Version 1.2, together with MS-DOS or PC-DOS Turbo Pascal
  15. 3.01A or higher (regular, 8087, or BCD version).  If you have Version 1.00,
  16. 1.01, or 1.1 of the Toolbox, see the file TBXFIX in DL 1 of the Borland SIG for
  17. the source code changes that will upgrade your copy to Version 1.2 (plus
  18. additional fixes).  If you have Version 3.00A or 3.00B of Turbo Pascal, arrange
  19. with Borland Customer Service to upgrade your copy of Turbo to 3.01A or higher
  20. (3.00A and 3.00B are not compatible with Turbo Database Toolbox).  The routines
  21. below will not work with earlier (pre-3.0) versions of Turbo Pascal, nor with
  22. Turbo Pascal for operating systems other than DOS.
  23.  
  24. Normally, when using the Turbo (Database) Toolbox with Turbo Pascal 3.0 and
  25. higher, only 15 total files (Toolbox files and other files/devices manipulated
  26. by the program) can be open at the same time, due to limitations in DOS.  The
  27. information below shows you how to have up to 96 total files open
  28. simultaneously under DOS 2.0 or 2.1, or 252 files open simultaneously under DOS
  29. 3.0 or higher.  This technique is totally internal to the Toolbox; after making
  30. the indicated Toolbox changes, you will not have to change the source code of
  31. your programs that use the Toolbox (except to add a compiler directive and an
  32. include file; see below).
  33.  
  34. The code below uses the routines in EXTEND.PAS, also in DL 1 of the Borland
  35. CompuServe SIG.  EXTEND.PAS shows how to use this technique for any kind of
  36. Turbo file, not just Toolbox files.  Your program can use EXTEND.PAS directly,
  37. in addition to the changes mentioned below for the Toolbox.  The 96 (or 252)
  38. limit of simultaneously open files will apply to the total of all Toolbox files
  39. and other files that your program uses.  For those interested in the technical
  40. underpinnings of this method, please see the documentation in EXTEND.PAS.
  41.  
  42. There are some other files in DL 1 of the Borland SIG that may be of interest.
  43. These files describe how to modify the Database Toolbox to extend it for
  44. various other purposes; e.g., FLUSH.ACC describes Toolbox modifications that
  45. provide automatic "flushing" of DataFiles and IndexFiles under DOS Turbo 3.0,
  46. to guard against file corruption in the event of a system crash, and BIGTRE.BOX
  47. shows how to use more than 65535 records per DataFile under DOS.  The
  48. modifications below have been tested with FLUSH.ACC, so you may use the
  49. FLUSH.ACC and EXTEND.ACC modifications together.  However, the BIGTRE.BOX
  50. modifications have not yet been examined with respect to FLUSH.ACC and
  51. EXTEND.ACC.  Try a "BRO/KEY:TOOLBOX" and a "BRO/KEY:ACCESS" to find these and
  52. other files in DL 1.
  53.  
  54. Note: If you are using both the EXTEND.ACC modifications and the FLUSH.ACC
  55. modifications, you must apply the FLUSH.ACC modifications first, THEN the
  56. modifications below.
  57.  
  58.  
  59.  
  60. MODIFYING ACCESS.BOX:
  61.  
  62. This method only works with Turbo 3.0 and higher.  Make the following
  63. modifications to the indicated procedures/functions in ACCESS.BOX or
  64. ACCESS3.BOX, whichever is intended for use with Turbo 3.0.  Check the comment
  65. header at the beginning of the file to ensure you are using the correct
  66. ACCESS.BOX.  Please BE SURE to make a backup copy of the ACCESS.BOX file before
  67. making these changes.
  68.  
  69.  
  70. 1. In GetRec:
  71. -------------
  72.  
  73. Add the following line immediately after the "begin":
  74.   UnExtend(DatF.F);
  75.  
  76. Add the following line immediately after the "BlockRead(...);" statement:
  77.   ReExtend(DatF.F);
  78.  
  79.  
  80. 2. In PutRec:
  81. -------------
  82.  
  83. Add the following line immediately after the "begin":
  84.   UnExtend(DatF.F);
  85.  
  86. Add the following line immediately after the "BlockWrite(...);" statement:
  87.   ReExtend(DatF.F);
  88.  
  89.  
  90. 3. In MakeFile:
  91. ---------------
  92.  
  93. Add the following line immediately after the "Move(...);" statement:
  94.   OpenExtend(DatF.F);
  95.  
  96.  
  97. 4. In OpenFile:
  98. ---------------
  99.  
  100. Add the following line immediately BEFORE the "GetRec(...);" statement:
  101.   OpenExtend(DatF.F);
  102.  
  103. Add the following line immediately after the "Move(...);" statement:
  104.   UnExtend(DatF.F);
  105.  
  106. Add the following line immediately after the "DatF.NumRec := ...;" statement:
  107.   ReExtend(DatF.F);
  108.  
  109.  
  110. 5. In CloseFile:
  111. ----------------
  112.  
  113. Add the following line immediately after the "PutRec(...);" statement:
  114.   UnExtend(DatF.F);
  115.  
  116. Add the following line immediately after the "Close(...);" statement:
  117.   ReExtend(DatF.F);
  118.  
  119.  
  120. NOTE: If you have modified ACCESS.BOX as per FLUSH.ACC, make the following
  121. additional changes:
  122.  
  123.  
  124. 6. In FlushFile:
  125. ----------------
  126.  
  127. Add the following line immediately BEFORE the "Seek(...);" statement:
  128.   UnExtend(DatF.F);
  129.  
  130. Add the following line immediately after the FIRST "MsDos(...);" statement:
  131.   ReExtend(DatF.F);
  132.  
  133.  
  134. 7. In FlushIndex:
  135. -----------------
  136.  
  137. Add the following line immediately BEFORE the "Seek(...);" statement:
  138.   UnExtend(IdxF.DataF.F);
  139.  
  140. Add the following line immediately after the "BlockWrite(..);" statement:
  141.   ReExtend(IdxF.DataF.F);
  142.  
  143.  
  144.  
  145. TO USE THIS TECHNIQUE:
  146.  
  147. Make the above modifications.  Then --
  148.  
  149. At the very top of your program, prior to the "program" statement, put the
  150. compiler directive {$F252}.  (You may use a value smaller than 252, if you
  151. wish.  Under DOS 2.0/2.1, values above 96 have no additional benefit.  Each
  152. larger value for the {$F} directive uses 2 additional bytes in the program's
  153. global data space.)  The value you specify for the {$F} directive is the
  154. maximum number of files you will be able to have open at the same time in your
  155. program.
  156.  
  157. In your program, PRIOR to the {$I ACCESS.BOX} (or {$I ACCESS3.BOX}), insert a
  158. line that says {$I EXTEND.PAS}, to include the EXTEND.PAS file (available in
  159. DL 1 of the Borland SIG).
  160.  
  161. Edit your CONFIG.SYS file (see the DOS manual for details), so that it includes
  162. a line that says "FILES=XXX".  XXX should be a number that is 3 greater than
  163. the value you specified for the {$F} directive (larger values will provide no
  164. additional benefit, with respect to your individual program), and should not
  165. exceed 99 (for DOS 2.0/2.1) or 255 (for DOS 3.0 and higher).  Under any version
  166. of DOS, the minimum allowable value for XXX is 8.  Then, reboot your computer
  167. so that the FILES=XXX parameter takes hold.  That's it!
  168.  
  169. Note: EXTEND.PAS uses a typed constant whose value changes during the course of
  170. execution.  Consequently, when compiling any program that uses EXTEND.PAS
  171. (including programs that use the EXTEND.ACC technique), you must either: 1)
  172. compile the program in memory and run it ONCE only, or 2) compile the program
  173. to a .COM file, and execute the .COM file.  The program will bomb if you: 1)
  174. compile the program in memory and then run the program more than once, or 2)
  175. compile and run the program in memory, and then immediately compile to a .COM
  176. file without first leaving and restarting Turbo.
  177.  
  178. Running the sample program below will tell you the maximum number of files you
  179. can have open at once (usually 96 or 252, unless a resident program has files
  180. open, or unless there are some orphaned files due to previous program error).
  181. This program takes a while to run, due to the heavy disk I/O, so running it on
  182. a hard disk (or, even better, a RAM disk) is recommended.  Make sure that you
  183. are running the program in a subdirectory, so that you don't run up against the
  184. DOS limit on the number of allowable files in the root directory of a drive.
  185. Have fun!
  186.  
  187.  
  188.  
  189. Many thanks to Bela Lubkin (CompuServe 76703,3015) for masterminding this idea,
  190. and to Kim Kokkonen (CompuServe 72457,2131) and Scott Bussinger (CompuServe
  191. 72247,2671) for helping me debug it.  If you have any questions, comments, or
  192. trouble with the above changes, please feel free to contact me on the Borland
  193. SIG or via EasyPlex on CompuServe.  I sincerely hope the above information is
  194. useful to you!
  195.  
  196. Change Log:
  197.  
  198.   Version 1.1: Fixes an important bug, pointed out by Scott Bussinger, in the
  199.                changes to MakeFile and OpenFile, above.  Also, adds a caveat
  200.                about compiling programs that use EXTEND.PAS (including
  201.                EXTEND.ACC).
  202.  
  203. ******************************************************************************)
  204.  
  205. {$F252}
  206.  
  207. {Turbo Access constants}
  208. const
  209.   MaxDataRecSize =  17;
  210.   MaxKeyLen      =  10;
  211.   PageSize       =  24;
  212.   Order          =  12;
  213.   PageStackSize  =  10;
  214.   MaxHeight      =   4;
  215.  
  216. {$I EXTEND.PAS}
  217. {$I ACCESS.BOX}  {IMPORTANT: Or ACCESS3.BOX...whichever file you modified}
  218.  
  219. const
  220.   MaxCount = 255;
  221.   SampleData: string[16] = 'Some sample data';
  222. var
  223.   fn: string[14];
  224.   f: array[1..MaxCount] of DataFile;
  225.   i, count, dataRef: Integer;
  226.   temp: File;
  227. begin
  228.   writeln('Opening files...');
  229.   i := 0;
  230.   repeat
  231.     i := i + 1;
  232.     Str(i, fn);
  233.     fn := 'junk' + fn + '.dat';
  234.     Assign(temp, fn);
  235.     {$I-} Rewrite(temp); {$I+}
  236.     OK := IOResult = 0;
  237.     if OK then
  238.       begin
  239.         Close(temp);
  240.         MakeFile(f[i], fn, MaxDataRecSize)
  241.       end
  242.   until not OK;
  243.   count := i - 1;
  244.   writeln('Successfully opened ', count, ' files at the same time.  ',
  245.           'Writing to each file...');
  246.   for i := 1 to count do AddRec(f[i], dataRef, SampleData);
  247.   writeln('Closing each file...');
  248.   for i := 1 to count do CloseFile(f[i]);
  249.   writeln('Erasing each file...');
  250.   for i := 1 to count do
  251.     begin
  252.       Str(i, fn);
  253.       Assign(temp, 'junk' + fn + '.dat');
  254.       Erase(temp)
  255.     end;
  256.   writeln('Done.')
  257. end.